package org.feng.utils;

import cn.dev33.satoken.stp.StpUtil;
import org.apache.commons.lang.StringUtils;
import org.feng.constant.CommonConstant;
import org.feng.enums.Response;
import org.feng.exception.ServiceException;

/**
 * 用户工具类
 *
 * @author by feng
 */
public class UserUtil {
    /**
     * 获取用户id
     *
     * @return userId
     */
    public static Long getUserId() {
        String token = HttpUtils.getRequest().getHeader(CommonConstant.TOKEN_CODE);
        if (StringUtils.isNotBlank(token)) {
            return StpUtil.getLoginIdAsLong();
        }
        throw new ServiceException(Response.USER_NOT_LOGIN);
    }
}
